package org.itcast.travel.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.itcast.travel.mapper.PlaceMapper;
import org.itcast.travel.pojo.PageBean;
import org.itcast.travel.pojo.Place;
import org.itcast.travel.pojo.PlaceQueryParam;
import org.itcast.travel.service.PlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PlaceServicelImpl implements PlaceService {
    @Autowired
    private PlaceMapper placeMapper;

    @Override
    public PageBean placepage(PlaceQueryParam placeQueryParam) {
        PageHelper.startPage(placeQueryParam.getPage(), placeQueryParam.getPageSize());
        Page<Place> placePage = placeMapper.page(placeQueryParam);
        return new PageBean(placePage.getTotal(), placePage.getResult());

    }

    @Override
    public void deletByIds(List<Integer> ids) {
        placeMapper.deletById(ids);
    }

    @Override
    public void add(Place place) {
        placeMapper.add(place);
    }

    @Override
    public Place getByid(Integer id) {
        Place placeInfo = placeMapper.getById(id);
        return placeInfo;
    }

    @Override
    public void update(Place place) {
        placeMapper.update(place);
    }
}
